package com.example.demo.item.web;

import com.example.demo.item.entity.Item;
import com.example.demo.item.service.ItemService;
import com.example.demo.utils.RespMessage;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.UUID;


@RestController
@RequestMapping("/item")
public class ItemController {

    @Autowired
    private ItemService itemService;
    /**
     * 查询所有商品
     * @return
     */
    @RequestMapping("/list")
    public RespMessage findList(Item item) {
        long start = System.currentTimeMillis();
        PageHelper.startPage(1, 100);
        List<Item> list = itemService.findList(item);
        long end = System.currentTimeMillis();
        System.out.println(end - start + "ms");
        return RespMessage.success("成功", list);
    }


    /**
     * 查询所有单个商品
     * @return
     */
    @RequestMapping("/get")
    public RespMessage findOne(String id){

        Item item = itemService.findOne(id);

        return RespMessage.success("成功",item);
    }

    /**
     * 删除单个商品
     * @return
     */
    @RequestMapping("/remove")
    public RespMessage remove(String id){

        itemService.remove(id);

        return RespMessage.success("成功");
    }

    /**
     * 添加商品
     * @return
     */
    @RequestMapping("/save")
    public RespMessage save(Item item){



        itemService.save(item);
        return RespMessage.success("成功");
    }

    /**
     * 修改商品
     * @return
     */
    @RequestMapping("/update")
    public RespMessage update(Item item){

        itemService.update(item);
        return RespMessage.success("成功");
    }

    /**
     * 插入10万条数据
     * @return
     */
    @RequestMapping("/insert")
    public RespMessage insert() {
        itemService.insert();
        return RespMessage.success("成功","数据");
    }



}
